package com.fs.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fs.pojo.WhDetailed;
import com.fs.pojo.WhWarehousing;
import com.fs.service.SysPostService;
import com.fs.service.WhDetailedService;
import com.fs.service.WhWarehousingService;
import com.fs.vo.Condition;
import com.fs.vo.ResponseData;
import com.fs.vo.ResultEnums;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
@RequestMapping("/system")
public class WhWarehousingControll {
    @Resource
    private WhWarehousingService service;
    @Resource
    private WhDetailedService whDetailedService;

    @Resource
    private SysPostService sysPostService;
//    @Resource
//    private SysDeptService sysDeptService;

    /**
     * 初始化和分页条件查询入库单
     *
     * @param condition
     * @return
     */
    @PostMapping("/notice/index")
    public PageInfo<WhWarehousing> selectPage(@RequestBody Condition<WhWarehousing> condition) {
        return service.selectPage(condition);
    }

    /**
     * 初始化和分页查询物品明细单
     *
     * @param condition
     * @return
     */
    @PostMapping("/notice/whdetailed")
    public ResponseData<Page> selectWds(@RequestBody Condition<WhWarehousing> condition) {
        return new ResponseData<Page>(ResultEnums.OK, whDetailedService.selectDatail(condition));
    }

    /**
     * 根据id查询单个入库单
     *
     * @param warehousingEntryId
     * @return
     */
    @GetMapping("/notice/add/{warehousingEntryId}")
    public WhWarehousing selectOne(@PathVariable int warehousingEntryId) {
        return service.selectOneById(warehousingEntryId);
    }

    /**
     * 根据id删除单个入库单
     *
     * @param warehousingEntryId
     */
    @DeleteMapping("/notice/delete/{warehousingEntryId}")
    public void deleteWh(@PathVariable int warehousingEntryId) {
        service.deleteWh(warehousingEntryId);
    }

    /**
     * 根据id删除物品明细表
     *
     * @param deleteWd
     */
    @DeleteMapping("/notice/{deleteWd}")
    public void deleteWd(@PathVariable int deleteWd) {
        whDetailedService.deleteDatail(deleteWd);
    }

    /**
     * 新增入库方法
     *
     * @param whWarehousing
     */
    @PostMapping("/notice/add")
    public void addWh(@RequestBody WhWarehousing whWarehousing) {
        System.out.println(whWarehousing);
        service.addWh(whWarehousing);
    }

    /**
     * 修改入库单表
     *
     * @param whWarehousing
     */
    @PutMapping("/notice/update")
    public void updateWh(@RequestBody WhWarehousing whWarehousing) {
        service.changeById(whWarehousing);
    }

    /**
     * 查询人员职位表
     *
     * @return
     */
//    @GetMapping("/system/user/selectPost")
//    public List<SysPost> selectPost() {
//        return sysPostService.select();
//    }

}
